// 一定是异步链接数据库，否则无法返回数据库对象
const MongoClient = require('mongodb').MongoClient;
const dbName = 'xhpx' // 库名
const url = "mongodb://localhost:27017/"+dbName;

const p = new Promise((resolve, reject) => {
    MongoClient.connect(url, (err, dbs) => {
        if (err) throw err;
        let dbo = dbs.db(dbName);
        resolve({dbo:dbo, dbs:dbs});
    });
})

module.exports = p;